#include "e_notedlg.h"
#include "ui_e_notedlg.h"

#include "e_grbdef.h"

e_notedlg::e_notedlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::e_notedlg)
{
    ui->setupUi(this);
    homePath=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
    if(QFile::exists(homePath+e_note))
    {
        loadNote();
    }
}

e_notedlg::~e_notedlg()
{
    delete ui;
}

void e_notedlg::on_btn_save_clicked()
{
    noteContent=ui->textEdit->toPlainText();
    saveNote();
}

void e_notedlg::loadNote()
{
    QFile file(homePath+e_note);
    if(file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        QTextStream txt(&file);
        txt.setCodec("UTF-8");
        noteContent=txt.readAll();
        ui->textEdit->setText(noteContent);
    }
}
void e_notedlg::saveNote()
{
    QFile file(homePath+ e_note);
    if(file.open(QIODevice::WriteOnly|QIODevice::Text))
    {
        QTextStream txt(&file);
        txt.setCodec("UTF-8");
        txt<<noteContent;
        file.close();
    }
}
